import re

# 写一个正则表达式,匹配座机号码? 比如: 0755-77777777    010-87878787  0312-7806812

# () 表示一个整体,表示分组,然后捕获
tel = "0755-77777777"
tel1 = "010-87878787"
tel2 = "0312-7806812"
pattern = '(\d{3,4})-(\d{7,8})'

# print(re.search(pattern,tel))  # <re.Match object; span=(0, 13), match='0755-77777777'>
# print(re.search(pattern,tel1))  # <re.Match object; span=(0, 12), match='010-87878787'>
# print(re.search(pattern,tel2))  # <re.Match object; span=(0, 12), match='0312-7806812'>

result = re.search(pattern, tel)
print(result.group())  # 0755-77777777
print(result.group(1))  # 0755
print(result.group(2))  # 77777777
print(result.groups())  # ('0755', '77777777')
